package com.urfresh.sp.flume.test;

import com.urfresh.sp.flume.configure.Application;
import org.springframework.context.annotation.Import;

@Import(Application.class)
public class MongoDBJDBC {

    public static void main(String args[]) {
//        MongoClient mongoClient = null;
//        try {
//            ServerAddress serverAddress = new ServerAddress("121.40.212.68", 27017);
//            List<ServerAddress> addrs = new ArrayList<ServerAddress>();
//            addrs.add(serverAddress);
//
//            MongoCredential credential = MongoCredential.createScramSha1Credential("report", "fair_db", "report".toCharArray());
//            List<MongoCredential> credentials = new ArrayList<MongoCredential>();
//            credentials.add(credential);
//
//            mongoClient = new MongoClient(addrs, credentials);
//
//            MongoDatabase mongoDatabase = mongoClient.getDatabase("fair_db");
//            System.out.println("Connect to database successfully");
//
////			MongoDatabase mongoDatabase = mongoClient.getDatabase("fair_db");
////			System.out.println("Connect to database successfully");
//
////			MongoCollection<Document> collection = mongoDatabase.getCollection("app_user");
////			System.out.println(collection.count());
////			FindIterable<Document> d = collection.find();
////			Iterator<Document> it = d.iterator();
////			while(it.hasNext()){
////				System.out.println(it.next().toJson());
////			}
////
////			Document doc = collection.find(eq("app_id", "NJ1UY2VS")).first();
////			if(doc!=null)
////				System.out.println(doc.toJson());
//            //���������ĵ�
//            /**
//             * 1. ��ȡ������FindIterable<Document>
//             * 2. ��ȡ�α�MongoCursor<Document>
//             * 3. ͨ���α�������������ĵ�����
//             * */
////	         FindIterable<Document> findIterable = collection.find();
////	         MongoCursor<Document> mongoCursor = findIterable.iterator();
////	         while(mongoCursor.hasNext()){
////	            System.out.println(":"+mongoCursor.next());
////	         }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            mongoClient.close();
//        }


//        MongoClient client = new MongoClient(
//                new ServerAddress("121.40.212.68", 27017),
//                Arrays.asList(MongoCredential.createCredential("report", "fair_db", "report".toCharArray())),
//                MongoClientOptions.builder()
//                        .socketKeepAlive(true)
//                        .connectionsPerHost(10)
//                        .threadsAllowedToBlockForConnectionMultiplier(10)
//                        .connectTimeout(3000)
//                        .maxWaitTime(3000)
//                        .socketTimeout(1000).build());
//
//        MongoTemplate template = new MongoTemplate(
//                new SimpleMongoDbFactory(client, "app_device")
//        );
//        System.out.println(template);
//        template.findAll(HashMap.class, "order_app");
//
//        Map firstOrder = template.findOne(Query.query(where("user").is("13162637210")).addCriteria(where("type").is("HOUR")).addCriteria(where("status").nin(Arrays.asList("DUE", "TIMEOUT", "CANCEL", "CANCEL_TO_REFUND", "REFUND"))).with(new Sort(Sort.Direction.ASC, "b_time")), HashMap.class, "order_app");

    }

}
